home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageStream / ImageStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.3 KB  |  513 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class ImageStream extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    private Image buffer;
  20.    private Image backImage;
  21.    private Image[] image;
  22.    // $FF: renamed from: b java.awt.Graphics
  23.    private Graphics field_0;
  24.    private boolean loaded = false;
  25.    private boolean isBackImage = false;
  26.    private boolean move = true;
  27.    // $FF: renamed from: on boolean
  28.    private boolean field_1 = true;
  29.    // $FF: renamed from: n int
  30.    private int field_2;
  31.    // $FF: renamed from: m int
  32.    private int field_3;
  33.    private int n_im = 1;
  34.    // $FF: renamed from: wi int
  35.    private int field_4;
  36.    // $FF: renamed from: he int
  37.    private int field_5;
  38.    private int wiImage;
  39.    private int heImage;
  40.    private int wiBack;
  41.    private int heBack;
  42.    private int pause = 50;
  43.    private int pause2 = 1000;
  44.    private int step = 2;
  45.    // $FF: renamed from: X int
  46.    private int field_6;
  47.    // $FF: renamed from: Y int
  48.    private int field_7;
  49.    private int decx;
  50.    private int decy;
  51.    private int mode = 1;
  52.    private String[] image_string;
  53.    private String backImageName;
  54.    private Color backColor;
  55.    private String statusBarText;
  56.    private AudioClip sound;
  57.    private AudioClip clicSound;
  58.    private AudioClip enterSound;
  59.    private boolean loopSound;
  60.    private String link;
  61.    // $FF: renamed from: fm java.awt.FontMetrics
  62.    private FontMetrics field_8;
  63.    private String enterText;
  64.    private boolean isEnterTextEnabled;
  65.    private int wiEnterText;
  66.    private int enterTextHeight;
  67.    private Color enterTextColor;
  68.  
  69.    public String getAppletInfo() {
  70.       return "Name: ImageStream\r\nAuthor: Taiji Software\r\n";
  71.    }
  72.  
  73.    public ImageStream() {
  74.       ((Component)this).addMouseListener(this);
  75.    }
  76.  
  77.    public void register() {
  78.       try {
  79.          URL u = new URL("http://www.taijisoftware.com");
  80.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  81.       } catch (Exception e) {
  82.          System.out.println(e);
  83.          this.stop();
  84.       }
  85.    }
  86.  
  87.    public void init() {
  88.       String codeBase = null;
  89.  
  90.       try {
  91.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  92.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  93.          codeBase = codeBase.toUpperCase();
  94.       } catch (Exception var9) {
  95.       }
  96.  
  97.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  98.          String regCode = ((Applet)this).getParameter("registration_code");
  99.          if (regCode == null) {
  100.             regCode = ((Applet)this).getParameter("reg_domain");
  101.             if (regCode == null) {
  102.                this.register();
  103.             } else {
  104.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  105.                   codeBase = "WWW." + codeBase;
  106.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  107.                   codeBase = codeBase.substring(4);
  108.                }
  109.  
  110.                char[] chars = new char[codeBase.length()];
  111.                codeBase.getChars(0, codeBase.length(), chars, 0);
  112.                String key = new String("haricot");
  113.                char[] chars2 = new char[key.length()];
  114.                key.getChars(0, key.length(), chars2, 0);
  115.  
  116.                for(int i = 0; i < codeBase.length(); ++i) {
  117.                   int j;
  118.                   if (i >= key.length()) {
  119.                      j = i - key.length() * (i / key.length());
  120.                   } else {
  121.                      j = i;
  122.                   }
  123.  
  124.                   chars[i] += chars2[j];
  125.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  126.                }
  127.  
  128.                String res = new String(chars);
  129.                if (!res.equalsIgnoreCase(regCode)) {
  130.                   this.register();
  131.                }
  132.             }
  133.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  134.             this.register();
  135.          }
  136.       }
  137.  
  138.       this.move = true;
  139.       this.getParameters();
  140.       if (this.sound != null) {
  141.          if (this.loopSound) {
  142.             this.sound.loop();
  143.             return;
  144.          }
  145.  
  146.          this.sound.play();
  147.       }
  148.  
  149.    }
  150.  
  151.    public void getParameters() {
  152.       this.field_4 = ((Component)this).getSize().width;
  153.       this.field_5 = ((Component)this).getSize().height;
  154.       String s = ((Applet)this).getParameter("image_number");
  155.       if (s != null) {
  156.          this.n_im = Integer.parseInt(s);
  157.       }
  158.  
  159.       this.image_string = new String[this.n_im + 1];
  160.  
  161.       for(int i = 1; i <= this.n_im; ++i) {
  162.          this.image_string[i] = ((Applet)this).getParameter("image" + Integer.toString(i));
  163.       }
  164.  
  165.       s = ((Applet)this).getParameter("pause");
  166.       if (s != null) {
  167.          this.pause = Integer.parseInt(s);
  168.       }
  169.  
  170.       s = ((Applet)this).getParameter("pause2");
  171.       if (s != null) {
  172.          this.pause2 = Integer.parseInt(s);
  173.       }
  174.  
  175.       s = ((Applet)this).getParameter("step");
  176.       if (s != null) {
  177.          this.step = Integer.parseInt(s);
  178.       }
  179.  
  180.       s = ((Applet)this).getParameter("mode");
  181.       if (s != null) {
  182.          this.mode = Integer.parseInt(s);
  183.       }
  184.  
  185.       this.backImageName = ((Applet)this).getParameter("background_image");
  186.       if (this.backImageName != null) {
  187.          this.isBackImage = true;
  188.       }
  189.  
  190.       ((Component)this).setBackground(this.getColor("background_color"));
  191.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  192.       s = ((Applet)this).getParameter("sound_name");
  193.       if (s != null) {
  194.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  195.       }
  196.  
  197.       s = ((Applet)this).getParameter("loop_sound");
  198.       if (s != null) {
  199.          if (s.equals("yes")) {
  200.             this.loopSound = true;
  201.          } else {
  202.             this.loopSound = false;
  203.          }
  204.       }
  205.  
  206.       s = ((Applet)this).getParameter("clic_sound_name");
  207.       if (s != null) {
  208.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  209.       }
  210.  
  211.       s = ((Applet)this).getParameter("enter_sound_name");
  212.       if (s != null) {
  213.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  214.       }
  215.  
  216.       this.link = ((Applet)this).getParameter("link");
  217.       this.enterText = ((Applet)this).getParameter("enter_text");
  218.       s = ((Applet)this).getParameter("enter_text_height");
  219.       if (s != null) {
  220.          this.enterTextHeight = Integer.parseInt(s);
  221.       }
  222.  
  223.       this.enterTextColor = this.getColor("enter_text_color");
  224.       if (this.enterTextColor == null) {
  225.          this.enterTextColor = Color.white;
  226.       }
  227.  
  228.    }
  229.  
  230.    public Color getColor(String param) {
  231.       String s = ((Applet)this).getParameter(param);
  232.       if (s != null) {
  233.          if (s.substring(0, 1).equals("#")) {
  234.             s = s.substring(1);
  235.             int i = Integer.parseInt(s, 16);
  236.             return new Color(i);
  237.          } else {
  238.             return null;
  239.          }
  240.       } else {
  241.          return null;
  242.       }
  243.    }
  244.  
  245.    public final void paint(Graphics g) {
  246.       if (this.loaded) {
  247.          this.field_0.clearRect(0, 0, this.field_4, this.field_5);
  248.          if (this.isBackImage) {
  249.             this.field_0.drawImage(this.backImage, (this.field_4 - this.wiBack) / 2, (this.field_5 - this.heBack) / 2, this);
  250.          }
  251.  
  252.          this.field_0.drawImage(this.image[this.field_2], this.decx, this.decy, this);
  253.          this.field_0.drawImage(this.image[this.field_3], this.decx, this.decy, this.decx + this.field_6, this.decy + this.heImage, 0, 0, this.field_6, this.heImage, this);
  254.          if (this.isEnterTextEnabled) {
  255.             this.field_0.drawString(this.enterText, (this.field_4 - this.wiEnterText) / 2, this.field_5 / 2);
  256.          }
  257.  
  258.          g.drawImage(this.buffer, 0, 0, this);
  259.       }
  260.  
  261.    }
  262.  
  263.    public final void update(Graphics g) {
  264.       this.paint(g);
  265.    }
  266.  
  267.    public void start() {
  268.       if (this.thread == null) {
  269.          this.move = true;
  270.          this.thread = new Thread(this);
  271.          this.thread.start();
  272.       }
  273.  
  274.    }
  275.  
  276.    public void stop() {
  277.       if (this.thread != null) {
  278.          this.move = false;
  279.          this.thread = null;
  280.       }
  281.  
  282.       if (this.sound != null) {
  283.          this.sound.stop();
  284.       }
  285.  
  286.    }
  287.  
  288.    // $FF: renamed from: n2 (int) int
  289.    public int method_0(int n) {
  290.       ++n;
  291.       return n > this.n_im ? 1 : n;
  292.    }
  293.  
  294.    public void run() {
  295.       if (!this.loaded) {
  296.          this.image = new Image[this.n_im + 1];
  297.          MediaTracker tracker = new MediaTracker(this);
  298.  
  299.          for(int i = 1; i <= this.n_im; ++i) {
  300.             this.image[i] = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image_string[i]);
  301.          }
  302.  
  303.          for(int i = 1; i <= this.n_im; ++i) {
  304.             tracker.addImage(this.image[i], 0);
  305.          }
  306.  
  307.          if (this.isBackImage) {
  308.             this.backImage = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.backImageName);
  309.             tracker.addImage(this.backImage, 0);
  310.          }
  311.  
  312.          try {
  313.             tracker.waitForAll();
  314.             this.loaded = !tracker.isErrorAny();
  315.          } catch (Exception e) {
  316.             System.err.println(e);
  317.          }
  318.  
  319.          if (!this.loaded) {
  320.             this.stop();
  321.          }
  322.       }
  323.  
  324.       this.wiImage = this.image[1].getWidth(this);
  325.       this.heImage = this.image[1].getHeight(this);
  326.       this.decx = (this.field_4 - this.wiImage) / 2;
  327.       this.decy = (this.field_5 - this.heImage) / 2;
  328.       if (this.isBackImage) {
  329.          this.wiBack = this.backImage.getWidth(this);
  330.          this.heBack = this.backImage.getHeight(this);
  331.       }
  332.  
  333.       this.buffer = ((Component)this).createImage(this.field_4, this.field_5);
  334.       this.field_0 = this.buffer.getGraphics();
  335.       this.field_0.setColor(this.enterTextColor);
  336.       String fontName = ((Applet)this).getParameter("enter_text_font");
  337.       if (fontName == null) {
  338.          fontName = "TimesRoman";
  339.       }
  340.  
  341.       int style = 1;
  342.       String s = ((Applet)this).getParameter("enter_text_style");
  343.       if (s != null) {
  344.          if (s.equals("bold")) {
  345.             style = 1;
  346.          } else if (s.equals("italic")) {
  347.             style = 2;
  348.          } else if (s.equals("bold_italic")) {
  349.             style = 3;
  350.          } else {
  351.             style = 0;
  352.          }
  353.       }
  354.  
  355.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  356.       this.field_8 = this.field_0.getFontMetrics();
  357.       if (this.enterText != null) {
  358.          this.wiEnterText = this.field_8.stringWidth(this.enterText);
  359.       }
  360.  
  361.       this.field_2 = 1;
  362.       this.field_3 = this.method_0(this.field_2);
  363.       switch (this.mode) {
  364.          case 1:
  365.             this.field_6 = 0;
  366.             break;
  367.          case 2:
  368.             this.field_6 = this.wiImage;
  369.       }
  370.  
  371.       while(this.move) {
  372.          while(this.field_1) {
  373.             ((Component)this).repaint();
  374.  
  375.             try {
  376.                Thread.sleep((long)this.pause);
  377.             } catch (InterruptedException var9) {
  378.                this.stop();
  379.             }
  380.  
  381.             switch (this.mode) {
  382.                case 1:
  383.                   if (this.field_6 + this.step <= this.wiImage) {
  384.                      this.field_6 += this.step;
  385.                   } else {
  386.                      this.field_6 = this.wiImage;
  387.                      ((Component)this).repaint();
  388.  
  389.                      try {
  390.                         Thread.sleep((long)this.pause2);
  391.                      } catch (InterruptedException var8) {
  392.                         this.stop();
  393.                      }
  394.  
  395.                      this.field_6 = 0;
  396.                      this.field_2 = this.method_0(this.field_2);
  397.                      this.field_3 = this.method_0(this.field_3);
  398.                   }
  399.                   break;
  400.                case 2:
  401.                   if (this.field_6 - this.step > 0) {
  402.                      this.field_6 -= this.step;
  403.                   } else {
  404.                      this.field_6 = 0;
  405.                      ((Component)this).repaint();
  406.  
  407.                      try {
  408.                         Thread.sleep((long)this.pause2);
  409.                      } catch (InterruptedException var7) {
  410.                         this.stop();
  411.                      }
  412.  
  413.                      this.field_6 = this.wiImage;
  414.                      this.field_2 = this.method_0(this.field_2);
  415.                      this.field_3 = this.method_0(this.field_3);
  416.                   }
  417.             }
  418.  
  419.             if (!this.field_1) {
  420.             }
  421.          }
  422.  
  423.          try {
  424.             Thread.sleep(100L);
  425.          } catch (InterruptedException var5) {
  426.             this.stop();
  427.          }
  428.       }
  429.  
  430.    }
  431.  
  432.    public URL giveURL(String url) {
  433.       try {
  434.          if (url.toUpperCase().startsWith("HTTP")) {
  435.             return new URL(url);
  436.          } else if (url.toUpperCase().startsWith("FTP")) {
  437.             int p = url.indexOf(":");
  438.             int p2 = url.indexOf(":", p + 1);
  439.             if (p2 != -1) {
  440.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  441.             }
  442.  
  443.             p = url.indexOf("%40");
  444.             if (p != -1) {
  445.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  446.             }
  447.  
  448.             return new URL(url);
  449.          } else {
  450.             return new URL(((Applet)this).getCodeBase(), url);
  451.          }
  452.       } catch (MalformedURLException e) {
  453.          System.out.println(e);
  454.          return null;
  455.       }
  456.    }
  457.  
  458.    public void mouseClicked(MouseEvent e) {
  459.    }
  460.  
  461.    public void mouseEntered(MouseEvent e) {
  462.       if (this.enterText != null) {
  463.          this.isEnterTextEnabled = true;
  464.          ((Component)this).repaint();
  465.       }
  466.  
  467.       if (this.statusBarText != null) {
  468.          ((Applet)this).showStatus(this.statusBarText);
  469.       }
  470.  
  471.       if (this.enterSound != null) {
  472.          this.enterSound.play();
  473.       }
  474.  
  475.       if (this.link != null) {
  476.          ((Component)this).setCursor(new Cursor(12));
  477.       }
  478.  
  479.    }
  480.  
  481.    public void mouseExited(MouseEvent e) {
  482.       if (this.isEnterTextEnabled) {
  483.          this.isEnterTextEnabled = false;
  484.          ((Component)this).repaint();
  485.       }
  486.  
  487.       if (this.link != null) {
  488.          ((Component)this).setCursor(new Cursor(0));
  489.       }
  490.  
  491.    }
  492.  
  493.    public void mousePressed(MouseEvent e) {
  494.       if (this.clicSound != null) {
  495.          this.clicSound.play();
  496.       }
  497.  
  498.       if (this.link != null) {
  499.          String target = ((Applet)this).getParameter("target");
  500.          if (target == null) {
  501.             target = "_blank";
  502.          }
  503.  
  504.          URL u = this.giveURL(this.link);
  505.          ((Applet)this).getAppletContext().showDocument(u, target);
  506.       }
  507.  
  508.    }
  509.  
  510.    public void mouseReleased(MouseEvent e) {
  511.    }
  512. }
  513.